<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
!is_numeric($_GET['page']) ? $page = 1 : $page = (int)($_GET['page']);
!is_numeric($_GET['Level']) ? $Level = 0 : $Level = $_GET['Level'];
$PageCount = $UsersManagePage;
$_GET['Word'] == '' ? $InWord = '请输入用户名或公司名称' : $InWord = $_GET['Word'];

$nUrl = 'UsersManage.php?Word=' . $_GET['Word'] . '&page=' . $page . '&Level=' . $Level;
switch ($_GET['Action']){
	case 'An':
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "user` SET `UserAudit` = '0' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,1,'取消会员审核(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
			MsgBox (0,'',$nUrl);		
		}else{
			AdminLog(1,1,'取消会员审核(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
			MsgBox (1,'操作失败！','-1');	
		}
		break;
	case 'Ay':
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "user` SET `UserAudit` = '1' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,1,'通过会员审核(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
			MsgBox (0,'',$nUrl);		
		}else{
			AdminLog(1,1,'通过会员审核(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
			MsgBox (1,'操作失败！','-1');	
		}
		break;
	case 'Del':
		if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "user` WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1;")){
			AdminLog(3,1,'删除会员(ID:' . $_GET['ID'] . ')，结果：删除成功！'); 
			MsgBox (0,'',$nUrl);		
		}else{
			AdminLog(3,1,'删除会员(ID:' . $_GET['ID'] . ')，结果：删除失败！'); 
			MsgBox (1,'删除失败！','-1');	
		}
		break;
	case 'AllDel':
		$DelID = $_POST['DelID'];
		if ($DelID=='') MsgBox (1,'请选择要删除的会员！','-1');
		$DelID = implode(',',$DelID); //Array转成字串	
		if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "user` WHERE `ID` IN (" . $DelID . ")")){
			AdminLog(3,$Lang,'批量删除会员(ID:' . $DelID . ')，结果：操作成功！'); 
			MsgBox (1,'操作成功！',$nUrl);		
		} else {
			AdminLog(3,$Lang,'批量删除会员，结果：操作失败！'); 
			MsgBox (1,'操作失败！','-1');		
		}	
		break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script language="javascript">
function Check() {
	if (document.form2.Word.value == "" || document.form2.Word.value == "请输入用户名或公司名称"){
		alert("请输入用户名或公司名称！");
		document.form2.Word.focus();
		return false;
	}
}
function CheckAll(form) { //复选框全选/取消
	for (var i=0;i<form.elements.length;i++) { 
		var e = form.elements[i]; 
		if (e.Name != "chkAll"&&e.disabled!=true) 
		e.checked = form.chkAll.checked; 
	} 
} 
</script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="Notodd">
	<td height="25">
    <table border="0" align="right" cellpadding="0" cellspacing="0">
        <form id="form2" name="form2" method="get" action="UsersManage.php" onSubmit="return Check()">
        <tr>
        <td>查找会员：</td>
        <td>
<select OnChange="window.open(this.options[this.selectedIndex].value,'_self')" size="1">
<?php
echo '<option value="UsersManage.php">==全部会员==</option>' . "\n";
foreach ($UserLevel as $i => $value){
	if($Level!=$value[1]){
		echo '<option value="UsersManage.php?Level=' . $value[1] . '">' . $value[0] . '</option>' . "\n";
	}else{
		echo '<option selected="selected" value="UsersManage.php?Level=' . $value[1] . '">' . $value[0] . '</option>' . "\n";
	}
}
unset($i,$value);
?>	
</select>		
		</td>
        <td><input name="Word" type="text" id="Word" onClick="this.value='';" onMouseOver="this.select();" value="<?php echo $InWord?>" size="22" maxlength="20" /></td>
        <td><input type="submit" name="button2" id="button2" value="查找" /></td>
        <td>
			<input type="button" value="刷新" onClick="javascript:location.href='UsersManage.php'">
			<input type="button" value="添加会员" onClick="javascript:location.href='UsersAdd.php?Lang=<?php echo $Lang?>'">
			<input type="button" value="权限管理" onClick="javascript:location.href='UsersPermissions.php?Lang=<?php echo $Lang?>'">		
		</td>
        </tr>
        <input name="Level" type="hidden" value="<?php echo $Level?>" />
        </form>
    </table>
    </td>
</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form id="form1" name="form1" method="post" action="?Action=AllDel&page=<?php echo $page?>&Word=<?php echo $Word?>&Level=<?php echo $Level?>">
  <tr>
    <td colspan="5" align="center" class="Main_Title">会员管理</td>
  </tr>
  <tr class="odd">
    <td align="center" width="50"><input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value="checkbox"></td>
    <td height="20" align="center"><strong>用户名(邮箱)</strong></td>
    <td align="center"><strong>注册时间(注册IP)</strong></td>
    <td align="center"><strong>最后登录时间[IP地址](登录次数)</strong></td>
    <td align="center"><strong>管理选项</strong></td>
  </tr>
<?php
$SQL = "SELECT `ID`,`UserName`,`UserTrueName`,`UserEmail`,`UserLogin`,`UserLoginIP`,`UserLoginTime`,`UserRegIP`,`UserRegTime`,`UserAudit` FROM `" . $dbprefix . "user` WHERE 1=1 ";
if($Level != 0) $SQL .= "&& `UserLevel` = '" . $Level . "' ";
if($_GET['Word']!='') $SQL .="&& (`UserName` LIKE '%" . $_GET['Word'] . "%' || `UserCompany` LIKE '%" . $_GET['Word'] . "%') ";
$RsCount = count($db->SelectSQL($SQL)); //总记录数
$SQL .= "ORDER BY `ID` DESC ";
$SQL .= "LIMIT " . ($page-1)*$PageCount . " , " . $PageCount . " ";
$Rsn = $db->SelectSQL($SQL);
if (count($Rsn)==0){echo '<tr class="odd"><td height="50" colspan="5" align="center">没有相关数据！</td></tr>';}
foreach ($Rsn as $i => $Rs){
	Html($Rs);
	$Rs[9] == 1 ? $nAudit = '<a href="?Word=' . $_GET['Word'] . '&Level=' . $Level . '&Action=An&ID=' . $Rs[0] . '&page=' . $page . '&ID=' . $Rs[0] . '">取消审核</a>' : $nAudit = '<a href="?Word=' . $_GET['Word'] . '&Level=' . $Level . '&Action=Ay&ID=' . $Rs[0] . '&page=' . $page . '&ID=' . $Rs[0] . '"><font color="#FF0000">通过审核</font></a>';
	$nAudit .= '&nbsp|&nbsp;<a href="UsersUpDate.php?ID=' . $Rs[0] . '">修改</a>&nbsp;|&nbsp;';
	$nAudit .= '<a onClick="return confirm(\'确定删除该会员吗？\');" href="?Word=' . $_GET['Word'] . '&Level=' . $Level . '&Action=Del&ID=' . $Rs[0] . '&page=' . $page . '">删除</a>';
	echo '<tr class="odd">
    <td align="center"><input name="DelID[]" type="checkbox" id="DelID[]" value="' . $Rs[0] . '"></td>
    <td height="20" align="left"><a href="mailto:' . $Rs[3] . '">' . $Rs[1] . '</a></td>
    <td align="center">' . $Rs[8] . '(<a target="_blank" href="../inc/gettopost.php?Action=IP&IP=' . $Rs[7] . '">' . $Rs[7] . '</a>)</td>
    <td align="center">' . $Rs[6] . '[<a target="_blank" href="../inc/gettopost.php?Action=IP&IP=' . $Rs[7] . '">' . $Rs[5] . '</a>](<font color="#FF0000">' . $Rs[4] . '</font>)</td>
    <td align="center">' . $nAudit . '</td>
	</tr>';
}
unset($Rsn,$i,$Rs,$nAudit);
?>  
 <tr class="odd">
    <td height="20" align="center"><input type="submit" name="button" id="button" value="删除" onClick="return confirm('确定要删除所有选定的会员吗？');"  /></td>
    <td height="20" colspan="4" align="center"><?php echo pages('Word=' . $_GET['Word'] . '&Level=' . $Level);?></td>
    </tr>
  </form>
  </table> 
</body>
</html>
